/**
 * Created by PengWei on 2018/7/26.
 */


namespace game {
    import BaseCommand = mengdao.BaseCommand;

    /**
     * 登录
     */
    export class LoginProcessCommand extends BaseCommand {
        private _console:ConsoleMediator;

        public execute(data: any): void {
            if (Config.PASSED_SESSION) {
                let netService:NetService = this.get(NetService);
                netService.init(this.finishLogin, this, Config.server);
            } else {
                this.removeHtmlReload();
                // this.dispatchEventWith(UIEvent.OPEN,LoginView);//ask command不应该与View耦合
                this.onceContextListener(UIEvent.POP_BE_CLOSED, this.popBeClosed, this);

                //temp
                let layer = this.get(Layer)
                let console = new ConsoleMediator(this._context)
                layer.debugLayer.addChild(console.ui)
                console.ui.y = Config.STAGE_HEIGHT-console.ui.height;
            }
        }

        private popBeClosed(e: UIEvent): void {
            let view = e.data;
            // if (view == LoginView) {
            //     console.log('面板被关闭');
            //     console.log('执行游戏');
            // }
        }

        private removeHtmlReload(): void {
            let callFunc = window["game_removeReload"];
            if (callFunc) callFunc();
        }

        private finishLogin(): void {

        }
    }
}